<template>
  <el-dialog
    title="批量设置部位系数"
    :visible.sync="visible"
    :destroy-on-close="true"
    width="400px"
    :before-close="handleClose">
    <div class="dlg_wrap"><el-form class="rule-form" ref="form" inline :model="ruleForm"> <el-form-item label="系数" prop="workCount" class="short-input"><el-input-number style="width:100%" size="small" v-model="ruleForm.workCount" :min="0"></el-input-number></el-form-item><div class="form_tips">请确认，已选择<b class="fc_red">{{ids.length}}</b> 个部位，批量设置部位系数</div></el-form>
    </div>
    <span slot="footer" class="dialog-footer"><el-button @click="visible = false">取消</el-button><el-button type="primary" @click="sendSet">提交</el-button>
    </span>
  </el-dialog>
</template>
<script>
import { setWorkCount } from '@/api/api.js'
export default {
  props: {
    dialogVisibleWorkCountType: {
      type: Boolean,
      default: false
    },
    hospitalCode: {
      type: String,
      default: ''
    },
    ids: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      ruleForm: {
        workCount: ''
      }
    }
  },
  computed: {
    visible: {
      get() {
        return this.dialogVisibleWorkCountType
      },
      set(val) {
        this.$emit('update:dialogVisibleWorkCountType', val)
      }
    }
  },
  watch: {
    visible(val) {
      if (val) {
        this.ruleForm.workCount = ''
      }
    }
  },
  methods: {
    handleClose() {
      this.visible = false
    },
    // 提交设置
    sendSet() {
      const _ids = this.ids.map(item => item.id)
      const params = {
        hospitalCode: this.hospitalCode,
        ids: _ids,
        workCount: this.ruleForm.workCount.toString()
      }
      console.error('params', params)
      setWorkCount(params).then((res) => {
        if (res) {
          this.$message.success(res.message || '设置成功')
          this.visible = false
          this.$emit('refresh')
        }
      })
    }
  }
}
</script>
